/**
 * 业务类型表js
 */

$(function () {
    initialPage();
    getGrid();
});

function initialPage() {
    $(window).resize(function () {
        $('#dataGrid').bootstrapTable('resetView', {height: $(window).height() - 56});
    });
}

function getGrid() {
    $('#dataGrid').bootstrapTableEx({
        url: '../../rest/business/type/list?_' + $.now(),
        height: $(window).height() - 56,
        queryParams: function (params) {
            params.businessName = vm.keyword;
            return params;
        },
        columns: [
            {checkbox: true},
            {
                title: '序号', align: "center", width: "40px",
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {field: "businessName", title: "业务类型名称", width: "100px"},
            {
                field: "status", title: "状态", width: "100px", formatter: function (value) {
                    if (value == 1) {
                        return "停用"
                    } else
                        return "启用"
                }
            },
            {field: "createTime", title: "创建时间", width: "100px"},
            {
                title: "操作", formatter: function (value, row, index) {
                    var _html = '';
                    _html += '<a href="javascript:;" onclick="vm.edit(\'' + row.businessId + '\')" title="编辑"><i class="fa fa-pencil"></i></a>';
                    _html += '<a href="javascript:;" onclick="vm.remove(false,\'' + row.businessId + '\')" title="删除"><i class="fa fa-trash-o"></i></a>';
                    return _html;
                }
            }
        ]
    })
}

var vm = new Vue({
    el: '#dpLTE',
    data: {
        keyword: null
    },
    methods: {
        load: function () {
            $('#dataGrid').bootstrapTable('refresh');
        },
        save: function () {
            dialogOpen({
                title: '新增业务类型表',
                url: 'business/businesstype/add.html?_' + $.now(),
                width: '420px',
                height: '350px',
                yes: function (iframeId) {
                    top.frames[iframeId].vm.acceptClick();
                },
            });
        },
        edit: function (businessId) {
            dialogOpen({
                title: '编辑业务类型表',
                url: 'business/businesstype/edit.html?_' + $.now(),
                width: '420px',
                height: '350px',
                success: function (iframeId) {
                    top.frames[iframeId].vm.businessType.businessId = businessId;
                    top.frames[iframeId].vm.setForm();
                },
                yes: function (iframeId) {
                    top.frames[iframeId].vm.acceptClick();
                }
            });
        },
        remove: function (batch, businessId) {
            var ids = [];
            if (batch) {
                var ck = $('#dataGrid').bootstrapTable('getSelections');
                if (!checkedArray(ck)) {
                    return false;
                }
                $.each(ck, function (idx, item) {
                    ids[idx] = item.businessId;
                });
            } else {
                ids.push(businessId);
            }
            $.RemoveForm({
                url: '../../rest/business/type/remove?_' + $.now(),
                param: ids,
                success: function (data) {
                    vm.load();
                }
            });
        }
    }
})